package cn.edu.neusoft.myappos.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.edu.neusoft.myappos.Bean.MianCommentBean;
import cn.edu.neusoft.myappos.R;

public class MainCommentAdapter extends RecyclerView.Adapter {
    private  Context context;//上下文
    private LayoutInflater layoutInflater;//动态布局
    private List<MianCommentBean> list;//向rv中填充的数据
    //自定义 构造方法
    public MainCommentAdapter (Context context){
        this.context=context;
        layoutInflater=LayoutInflater.from(context);
    }

    //自定义 ViewHoder子类，容纳item视图
    public  class ViewHolder extends  RecyclerView.ViewHolder {
        TextView name,id,comment,time;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            id=itemView.findViewById(R.id.TextView811);
            comment=itemView.findViewById(R.id.TextView813);
            time=itemView.findViewById(R.id.TextView814);
        }
    }
    //自定义 设置数据list
    public void setList(List<MianCommentBean> list){
        this.list=list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    //为每个item填充数据，设置点击事件
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v=layoutInflater.inflate
                (R.layout.item,parent,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
        //取数据
        final MianCommentBean bean=list.get(position);
        if(bean==null)
            return;
        ViewHolder viewHolder=(ViewHolder)holder;
        viewHolder.id.setText(bean.getName());
        viewHolder.time.setText(bean.getName());
        viewHolder.comment.setText(bean.getComment());

    }

    @Override
    public int getItemCount() {
        if(list!=null)
            return list.size();
        else
            return 0;
    }

}
